package com.fjec.common.aliyun.api;

import com.alibaba.cloudapi.sdk.client.ApacheHttpClient;
import com.alibaba.cloudapi.sdk.enums.HttpMethod;
import com.alibaba.cloudapi.sdk.enums.Scheme;
import com.alibaba.cloudapi.sdk.model.ApiCallback;
import com.alibaba.cloudapi.sdk.model.ApiRequest;
import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.cloudapi.sdk.model.HttpClientBuilderParams;

public abstract class BaseAliyunApi extends ApacheHttpClient {

    public final static String TEST_ACCESS_KEY_ID = "203856687";
    public final static String TEST_SECRET = "nvipMZfZ5fHnGmfFh5vBxGqfalzxvt4r";

    public BaseAliyunApi(HttpClientBuilderParams params) {
        params.setScheme(Scheme.HTTPS);
        params.setHost(getHost());
        super.init(params);
    }

    public void req(byte[] body , ApiCallback callback) {
        ApiRequest request = new ApiRequest(getHttpMethod() , getPath(), body);
        request.setNeedSignature(true);
        sendAsyncRequest(request , callback);
    }

    public ApiResponse syncReq(byte[] body) {
        ApiRequest request = new ApiRequest(getHttpMethod() , getPath(), body);
        request.setNeedSignature(true);
        return sendSyncRequest(request);
    }

    public abstract String getHost();

    public abstract String getPath();

    public abstract HttpMethod getHttpMethod();
}
